<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Gets the type name of a variable in a way that is suitable for debugging</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.floatval.html">« floatval</a></li>
      <li style="float: right;"><a href="function.get-defined-vars.html">get_defined_vars »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.var.html">Variable handling 函数</a></li>
    <li>Gets the type name of a variable in a way that is suitable for debugging</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.get-debug-type" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">get_debug_type</h1>
  <p class="verinfo">(PHP 8)</p><p class="refpurpose"><span class="refname">get_debug_type</span> &mdash; <span class="dc-title">Gets the type name of a variable in a way that is suitable for debugging</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.get-debug-type-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>get_debug_type</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   Returns the resolved name of the PHP variable <code class="parameter">value</code>.
   This function will resolve objects to their class name, resources to their
   resource type name, and scalar values to their common name as would be used in type
   declarations.
  </p>
  <p class="para">
   This function differs from <span class="function"><a href="function.gettype.html" class="function">gettype()</a></span> in that it returns type names
   that are more consistent with actual usage, rather than those present for historical reasons.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.get-debug-type-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">value</code></dt>

     <dd>

      <p class="para">
       The variable being type checked.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.get-debug-type-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
     Possible values for the returned string are:

     <table class="doctable informaltable">
      
       <thead>
        <tr>
         <th>Type + State</th>
         <th>Return Value</th>
         <th>Notes</th>
        </tr>

       </thead>

       <tbody class="tbody">
        <tr>
         <td>null</td>
         <td>
          <code class="literal">&quot;null&quot;</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>Booleans (true or false)</td>
         <td>
          <code class="literal">&quot;bool&quot;</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>Integers</td>
         <td>
          <code class="literal">&quot;int&quot;</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>Floats</td>
         <td>
          <code class="literal">&quot;float&quot;</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>Strings</td>
         <td>
          <code class="literal">&quot;string&quot;</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>Arrays</td>
         <td>
          <code class="literal">&quot;array&quot;</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>Resources</td>
         <td>
          <code class="literal">&quot;resource (resourcename)&quot;</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>Resources (Closed)</td>
         <td>
          <code class="literal">&quot;resource (closed)&quot;</code>
         </td>
         <td>Example: A file stream after being closed with fclose.</td>
        </tr>

        <tr>
         <td>Objects from Named Classes</td>
         <td>
          The full name of the class including its namespace e.g. <code class="literal">Foo\Bar</code>
         </td>
         <td>-</td>
        </tr>

        <tr>
         <td>Objects from Anonymous Classes</td>
         <td>
          <code class="literal">&quot;class@anonymous&quot;</code>
         </td>
         <td>
          Anonymous classes are those created through the $x = new class { ... } syntax
         </td>
        </tr>

       </tbody>
      
     </table>

  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-function.get-debug-type-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5275">
    <p><strong>示例 #1 <span class="function"><strong>get_debug_type()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(</span><span style="color: #0000BB">null</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(</span><span style="color: #0000BB">0.1</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">([])&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'rb'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br />echo&nbsp;</span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">stdClass</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">get_debug_type</span><span style="color: #007700">(new&nbsp;class&nbsp;{})&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
null
bool
int
float
string
array
resource (stream)
resource (closed)
stdClass
class@anonymous
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.get-debug-type-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.gettype.html" class="function" rel="rdfs-seeAlso">gettype()</a> - 获取变量的类型</span></li>
    <li class="member"><span class="function"><a href="function.get-class.html" class="function" rel="rdfs-seeAlso">get_class()</a> - 返回对象的类名</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>